package Regex;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexPattern {
    public static void main(String[] args) throws UnknownHostException {
        String domain="www.baidu.com";
        InetAddress inetAddr=InetAddress.getByName(domain);
        String str=inetAddr.getHostAddress();
        //获得一个正则表达式对象
        Pattern p = Pattern.compile("((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)");
        //使用正则表达式对象处理指定字符串,并获得结果对象
        Matcher m = p.matcher(str);
        //从正则表达式结果对象中获得信息
        while (true){
            if(m.find()) {
                System.out.print(m.group());
            }else break;
        }
    }
}
